/***************************************************************************
 * 文件名:BaseDao.java<br>
 * 版本: <br>
 * 描述: <br>
 * 版权所有: <br>
 * //////////////////////////////////////////////////////// <br>
 * 创建者: robo<br>
 * 创建日期: 2010-11-10 <br>
 * 修改者: <br>
 * 修改日期: <br>
 * 修改说明: <br>
 **************************************************************************/
package com.sunwayhorizo.health.ets.base.common;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.sunwayhorizo.health.business.dto.ResultsDTO;

public class BaseDao implements IBaseDao{

	@PersistenceContext(unitName="sunwayhealthEts")
	protected EntityManager entityManager2;
	
	protected ResultsDTO dto = new ResultsDTO();
    
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public <T> T find(Class <T> entityClass, Object primaryKey){
       T obj = entityManager2.find(entityClass, primaryKey);
       return obj;
    }

    public void save(Object entity){
    	entityManager2.persist(entity);
    }

    public void update(Object entity){
    	entityManager2.merge(entity);
    }
    
	public void delete(Class<?> entityClass, Object primaryKey){
		entityManager2.remove(entityManager2.getReference(entityClass, primaryKey));
    }
	
    public void delete(Object entity){
    	entityManager2.remove(entityManager2.merge(entity));
    }
}


